package com.github.satant.job.config;

import com.github.satant.job.common.constants.RestCodeConstants;
import com.github.satant.job.common.msg.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author EricLin
 * @Date 2018-06-06 17:27
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 所有异常报错
     */
    @ExceptionHandler(value = Exception.class)
    public BaseResponse allExceptionHandler(HttpServletRequest request, Exception exception) {
        log.error("路径" + request.getRequestURI() + "出错" + exception.getMessage());
        return new BaseResponse(RestCodeConstants.INTER_ERROR,"路径" + request.getRequestURI() + "出错" + exception.getMessage());
    }
}
